package com.lgd.factoryattendance.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgd.factoryattendance.R;

import java.util.List;

/**
 * @Author lgd
 * @Date 2024/3/4 15:46
 * listview 自定义适配器  ------  超期工单
 */
public class CustomListAdapter extends BaseAdapter {
    private Context context;
    private List<List<String>> orderListItem;

    public CustomListAdapter(Context context, List<List<String>> orderListItem) {
        this.context = context;
        this.orderListItem = orderListItem;
    }

    @Override
    public int getCount() {
        return orderListItem == null ? 0 : orderListItem.size();
    }

    @Override
    public Object getItem(int position) {
        return orderListItem == null ? null : orderListItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = convertView;
        ViewHolder holder;
        if (rowView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            rowView = inflater.inflate(R.layout.overdue_order_list, parent, false);
            holder = new ViewHolder();
            holder.productProject_TV = rowView.findViewById(R.id.productProject_TV);
            holder.productACode_TV = rowView.findViewById(R.id.productACode_TV);
            holder.productModule_TV = rowView.findViewById(R.id.productModule_TV);
            holder.productTime_TV = rowView.findViewById(R.id.productTime_TV);
//            holder.productStatus_TV = rowView.findViewById(R.id.productStatus_TV);
            rowView.setTag(holder);
        } else {
            holder = (ViewHolder) rowView.getTag();
        }

        List<String> orderShowItem = orderListItem.get(position);
        if (orderShowItem != null && orderShowItem.size() >= 4) {
            holder.productProject_TV.setText(orderShowItem.get(0));
            holder.productACode_TV.setText(orderShowItem.get(1));
            holder.productModule_TV.setText(orderShowItem.get(2));
            holder.productTime_TV.setText(orderShowItem.get(3));
//            holder.productStatus_TV.setText(orderShowItem.get(4));
        }
        return rowView;
    }
    private static class ViewHolder {
        TextView productProject_TV;
        TextView productACode_TV;
        TextView productModule_TV;
        TextView productTime_TV;
        TextView productStatus_TV;
    }
}
